package com.bq.server.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.util.List;
import java.util.function.Function;

/**
 * Jackson 序列化处理
 *
 * @author: ChenSH
 * @date: Create by in 5:45 下午 2019/10/14
 */
public class JacksonPage<T> extends PageImpl<T> {
    public JacksonPage(List<T> content, Pageable pageable, long total) {
        super(content, pageable, total);
    }

    public JacksonPage(List<T> content) {
        super(content);
    }

    @JsonProperty("page")
    @Override
    public int getNumber() {
        return super.getNumber();
    }

    @Override
    @JsonIgnore
    public Pageable getPageable() {
        return super.getPageable();
    }
    @JsonIgnore
    @Override
    public Sort getSort() {
        return super.getSort();
    }


    @Override
    public <U> Page<U> map(Function<? super T, ? extends U> converter) {
        return new JacksonPage<>(getConvertedContent(converter), getPageable(), getTotalElements());
    }
}
